1 Carga de Datos

Cargamos los datasets.

1.1 Hurto 2017

data_hurto_raw <- read.csv("hurto.csv")
str(data_hurto_raw)
## 'data.frame':    185105 obs. of  20 variables:
##  $ Fecha             : Factor w/ 365 levels "01/01/2017 12:00:00 AM",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Departamento      : Factor w/ 32 levels "AMAZONAS","ANTIOQUIA",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ Municipio         : Factor w/ 901 levels "ABEJORRAL","ABREGO",..: 443 443 443 443 443 443 443 443 443 443 ...
##  $ Día               : Factor w/ 7 levels "Domingo","Jueves",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Hora              : Factor w/ 1390 levels "12/31/1899 01:00:00 AM",..: 1040 1040 229 346 346 346 116 801 801 623 ...
##  $ Barrio            : Factor w/ 13990 levels "       VDA.  ANDALUCIA",..: 5586 5586 5586 5990 7073 10005 2224 5586 9170 8286 ...
##  $ Zona              : Factor w/ 3 levels "OTRAS","RURAL",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ Clase.de.sitio    : Factor w/ 384 levels "-","AEROPUERTO",..: 382 382 382 382 382 382 382 382 382 84 ...
##  $ Arma.empleada     : Factor w/ 16 levels "-","ALUCINOGENOS",..: 3 3 3 14 4 14 14 14 4 14 ...
##  $ Móvil.Agresor     : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 6 12 2 2 2 14 2 ...
##  $ Móvil.Victima     : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 13 13 2 2 2 5 2 ...
##  $ Edad              : int  39 43 26 29 37 87 30 59 35 28 ...
##  $ Sexo              : Factor w/ 3 levels "-","FEMENINO",..: 3 3 2 2 3 3 3 3 3 3 ...
##  $ Estado.civil      : Factor w/ 7 levels "-","CASADO","DIVORCIADO",..: 6 6 5 6 2 2 5 5 6 6 ...
##  $ País.de.nacimiento: Factor w/ 84 levels "-","AFGANISTAN",..: 20 20 20 20 20 20 20 20 20 20 ...
##  $ Clase.de.empleado : Factor w/ 36 levels "-","AFRODESCENDIENTE",..: 17 17 17 17 26 30 26 26 26 17 ...
##  $ Profesión         : Factor w/ 168 levels "-","ADMINISTRACION  AGROINDUSTRIAL",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Escolaridad       : Factor w/ 8 levels "-","ANALFABETA",..: 5 4 5 5 5 5 5 5 5 5 ...
##  $ Código.DANE       : int  5001000 5001000 5001000 5001000 5001000 5001000 5001000 5001000 5001000 5001000 ...
##  $ Cantidad          : int  1 1 1 1 1 1 1 1 1 1 ...
head(data_hurto_raw)
##                    Fecha Departamento     Municipio     Día
## 1 01/01/2017 12:00:00 AM    ANTIOQUIA MEDELLÍN (CT) Domingo
## 2 01/01/2017 12:00:00 AM    ANTIOQUIA MEDELLÍN (CT) Domingo
## 3 01/01/2017 12:00:00 AM    ANTIOQUIA MEDELLÍN (CT) Domingo
## 4 01/01/2017 12:00:00 AM    ANTIOQUIA MEDELLÍN (CT) Domingo
## 5 01/01/2017 12:00:00 AM    ANTIOQUIA MEDELLÍN (CT) Domingo
## 6 01/01/2017 12:00:00 AM    ANTIOQUIA MEDELLÍN (CT) Domingo
##                     Hora                     Barrio   Zona Clase.de.sitio
## 1 12/31/1899 10:00:00 AM         LA CANDELARIA C-10 URBANA  VIAS PUBLICAS
## 2 12/31/1899 10:00:00 AM         LA CANDELARIA C-10 URBANA  VIAS PUBLICAS
## 3 12/31/1899 03:00:00 PM         LA CANDELARIA C-10 URBANA  VIAS PUBLICAS
## 4 12/31/1899 04:00:00 PM LA LOMA DE LOS BERNAL C-16 URBANA  VIAS PUBLICAS
## 5 12/31/1899 04:00:00 PM            MANRIQUE 1  C-4 URBANA  VIAS PUBLICAS
## 6 12/31/1899 04:00:00 PM          SURAMERICANA C-11 URBANA  VIAS PUBLICAS
##                 Arma.empleada        Móvil.Agresor Móvil.Victima Edad
## 1 ARMA BLANCA / CORTOPUNZANTE                A PIE         A PIE   39
## 2 ARMA BLANCA / CORTOPUNZANTE                A PIE         A PIE   43
## 3 ARMA BLANCA / CORTOPUNZANTE                A PIE         A PIE   26
## 4         SIN EMPLEO DE ARMAS       CONDUCTOR TAXI PASAJERO TAXI   29
## 5               ARMA DE FUEGO PASAJERO MOTOCICLETA PASAJERO TAXI   37
## 6         SIN EMPLEO DE ARMAS                A PIE         A PIE   87
##        Sexo Estado.civil País.de.nacimiento   Clase.de.empleado Profesión
## 1 MASCULINO  UNION LIBRE           COLOMBIA EMPLEADO PARTICULAR         -
## 2 MASCULINO  UNION LIBRE           COLOMBIA EMPLEADO PARTICULAR         -
## 3  FEMENINO      SOLTERO           COLOMBIA EMPLEADO PARTICULAR         -
## 4  FEMENINO  UNION LIBRE           COLOMBIA EMPLEADO PARTICULAR         -
## 5 MASCULINO       CASADO           COLOMBIA       INDEPENDIENTE         -
## 6 MASCULINO       CASADO           COLOMBIA          PENSIONADO         -
##   Escolaridad Código.DANE Cantidad
## 1  SECUNDARIA     5001000        1
## 2    PRIMARIA     5001000        1
## 3  SECUNDARIA     5001000        1
## 4  SECUNDARIA     5001000        1
## 5  SECUNDARIA     5001000        1
## 6  SECUNDARIA     5001000        1

1.2 Pobloacion por Municipio

data_municipios_raw <- read.csv("municipios.csv")
str(data_municipios_raw)
## 'data.frame':    1123 obs. of  112 variables:
##  $ DP     : int  5 5 5 5 5 5 5 5 5 5 ...
##  $ DPNOM  : Factor w/ 34 levels "","Amazonas",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ DPMP   : int  5001 5002 5004 5021 5030 5031 5034 5036 5038 5040 ...
##  $ MPIO   : Factor w/ 1041 levels "Abejorral","Abrego",..: 519 1 3 20 30 31 36 37 38 40 ...
##  $ X1985  : Factor w/ 1015 levels "0","1,024","1,116",..: 12 471 516 649 401 272 606 767 122 108 ...
##  $ X1986  : Factor w/ 1023 levels "0","1,026","1,055",..: 13 474 521 658 417 283 616 776 139 119 ...
##  $ X1987  : Factor w/ 1018 levels "0","1,059","1,093",..: 13 467 530 661 419 288 622 780 143 117 ...
##  $ X1988  : Factor w/ 1028 levels "0","1,094","1,130",..: 15 469 529 670 428 297 628 789 152 124 ...
##  $ X1989  : Factor w/ 1028 levels "0","1,011","1,011,952",..: 16 470 538 678 440 302 627 791 155 126 ...
##  $ X1990  : Factor w/ 1026 levels "0","1,030,294",..: 17 465 536 671 443 303 621 790 153 125 ...
##  $ X1991  : Factor w/ 1035 levels "0","1,039","1,046,745",..: 19 465 537 675 450 309 634 807 158 130 ...
##  $ X1992  : Factor w/ 1033 levels "0","1,032","1,060,949",..: 17 452 532 669 454 313 632 812 158 131 ...
##  $ X1993  : Factor w/ 1048 levels "0","1,070","1,072,677",..: 20 457 543 679 469 327 644 825 165 143 ...
##  $ X1994  : Factor w/ 1049 levels "0","1,081,892",..: 20 455 543 681 476 333 648 834 168 150 ...
##  $ X1995  : Factor w/ 1051 levels "0","1,009","1,088,918",..: 22 445 542 682 481 331 648 843 162 149 ...
##  $ X1996  : Factor w/ 1062 levels "0","1,061","1,094,276",..: 23 447 553 692 491 345 663 853 171 170 ...
##  $ X1997  : Factor w/ 1080 levels "0","1,098,589",..: 24 443 555 689 496 357 668 867 175 184 ...
##  $ X1998  : Factor w/ 1081 levels "0","1,102,552",..: 27 439 555 686 499 361 668 878 184 195 ...
##  $ X1999  : Factor w/ 1086 levels "0","1,034","1,106,762",..: 377 437 560 686 505 372 673 881 174 201 ...
##  $ X2000  : Factor w/ 1100 levels "0","1,070","1,093",..: 385 440 421 693 515 379 685 918 175 221 ...
##  $ X2001  : Factor w/ 1095 levels "0","1,084","1,106",..: 380 437 413 683 513 418 729 920 165 220 ...
##  $ X2002  : Factor w/ 1110 levels "0","1,075","1,123,862",..: 385 436 417 612 522 426 740 942 164 226 ...
##  $ X2003  : Factor w/ 1098 levels "0","1,065","1,130,964",..: 384 431 415 604 523 427 735 942 165 229 ...
##  $ X2004  : Factor w/ 1106 levels "0","1,055","1,138,545",..: 383 428 408 605 525 427 740 950 156 234 ...
##  $ X2005  : Factor w/ 1099 levels "0","1,048","1,146,498",..: 384 425 407 604 529 430 741 959 151 240 ...
##  $ X2006  : Factor w/ 1106 levels "0","1,042","1,154,642",..: 386 425 402 603 531 434 745 963 147 246 ...
##  $ X2007  : Factor w/ 1109 levels "0","1,004","1,035",..: 396 431 408 606 540 442 758 978 150 256 ...
##  $ X2008  : Factor w/ 1102 levels "1,017","1,029",..: 390 369 398 592 531 435 751 985 131 251 ...
##  $ X2009  : Factor w/ 1106 levels "1,022","1,029",..: 395 369 400 593 538 440 757 994 122 258 ...
##  $ X2010  : Factor w/ 1105 levels "1,004","1,015",..: 390 364 393 589 538 442 760 1005 105 266 ...
##  $ X2011  : Factor w/ 1111 levels "1,007","1,029",..: 390 360 389 585 541 447 763 1018 106 273 ...
##  $ X2012  : Factor w/ 1108 levels "1,000","1,041",..: 381 355 376 574 537 443 760 1018 100 269 ...
##  $ X2013  : Factor w/ 1107 levels "1,078","1,089",..: 381 344 371 569 540 445 762 1028 93 269 ...
##  $ X2014  : Factor w/ 1101 levels "1,090","1,105",..: 384 341 369 566 538 444 759 1027 90 272 ...
##  $ X2015  : Factor w/ 1105 levels "1,001,755","1,102",..: 380 339 360 568 541 443 761 1035 85 279 ...
##  $ X2016  : Factor w/ 1111 levels "1,013,389","1,094",..: 379 331 355 567 543 445 765 1055 80 282 ...
##  $ X2017  : Factor w/ 1100 levels "1,024,882","1,066",..: 378 327 349 561 542 443 762 1057 79 289 ...
##  $ X2018  : Factor w/ 1105 levels "1,036,134","1,038",..: 381 326 29 566 599 449 770 1075 81 295 ...
##  $ X2019  : Factor w/ 1107 levels "1,021","1,047,005",..: 379 315 27 562 600 450 773 1080 69 295 ...
##  $ X2020  : Factor w/ 1100 levels "1,006","1,057,445",..: 376 310 27 560 597 448 770 1079 63 296 ...
##  $ X1985.1: Factor w/ 973 levels "0","1,008","1,011",..: 80 827 875 282 897 834 239 125 329 482 ...
##  $ X1986.1: Factor w/ 981 levels "0","1,013","1,017",..: 78 826 878 285 911 844 230 127 336 481 ...
##  $ X1987.1: Factor w/ 967 levels "0","1,000","1,001",..: 86 787 903 274 923 836 216 122 326 461 ...
##  $ X1988.1: Factor w/ 977 levels "0","1,003","1,004",..: 89 787 916 285 939 883 222 125 333 459 ...
##  $ X1989.1: Factor w/ 969 levels "0","1,008,752",..: 90 785 908 288 938 883 230 129 336 461 ...
##  $ X1990.1: Factor w/ 991 levels "0","1,014","1,018",..: 98 795 930 287 962 910 230 139 335 467 ...
##  $ X1991.1: Factor w/ 987 levels "0","1,001","1,002",..: 106 790 930 290 965 912 227 146 338 471 ...
##  $ X1992.1: Factor w/ 984 levels "0","1,015","1,020",..: 106 791 932 287 155 919 223 276 339 479 ...
##  $ X1993.1: Factor w/ 992 levels "0","1,008","1,010",..: 112 790 934 281 157 947 220 287 331 482 ...
##  $ X1994.1: Factor w/ 1001 levels "0","1,020","1,026",..: 119 792 946 286 165 957 227 306 335 506 ...
##  $ X1995.1: Factor w/ 1011 levels "0","1,000","1,002",..: 129 795 962 291 174 976 234 335 336 524 ...
##  $ X1996.1: Factor w/ 1018 levels "0","1,010","1,014",..: 139 807 973 300 188 990 243 369 340 547 ...
##  $ X1997.1: Factor w/ 1037 levels "0","1,004","1,005",..: 149 823 992 305 202 1012 260 394 346 573 ...
##  $ X1998.1: Factor w/ 1028 levels "0","1,017","1,020",..: 147 816 1005 294 202 158 258 475 334 623 ...
##  $ X1999.1: Factor w/ 1048 levels "0","1,007","1,015",..: 156 832 1022 293 207 161 264 503 330 651 ...
##  $ X2000.1: Factor w/ 1051 levels "0","1,000","1,013",..: 305 841 1007 160 218 173 276 532 336 675 ...
##  $ X2001.1: Factor w/ 1059 levels "0","1,003","1,005",..: 313 837 1016 156 231 174 288 550 339 683 ...
##  $ X2002.1: Factor w/ 1051 levels "0","1,000","1,003",..: 320 836 1004 150 239 176 289 551 335 686 ...
##  $ X2003.1: Factor w/ 1056 levels "0","1,001","1,005",..: 324 839 1008 149 235 170 284 565 329 695 ...
##  $ X2004.1: Factor w/ 1059 levels "0","1,002","1,009",..: 333 846 1009 148 241 175 294 623 328 747 ...
##  $ X2005.1: Factor w/ 1054 levels "0","1,001","1,015",..: 329 842 998 144 243 179 296 631 315 749 ...
##  $ X2006.1: Factor w/ 1054 levels "0","1,000","1,018",..: 329 839 993 138 245 181 302 646 310 756 ...
##  $ X2007.1: Factor w/ 1071 levels "0","1,000","1,011",..: 341 850 1007 141 253 188 310 671 317 779 ...
##  $ X2008.1: Factor w/ 1057 levels "0","1,001","1,013",..: 345 844 996 138 260 194 431 666 314 769 ...
##  $ X2009.1: Factor w/ 1058 levels "0","1,009","1,011",..: 351 847 993 137 267 200 433 672 156 781 ...
##  $ X2010.1: Factor w/ 1058 levels "0","1,006","1,017",..: 358 855 996 133 271 201 440 686 149 834 ...
##  $ X2011.1: Factor w/ 1054 levels "0","1,002","1,004",..: 354 851 990 123 268 193 438 682 142 835 ...
##  $ X2012.1: Factor w/ 1059 levels "0","1,000","1,017",..: 360 854 956 127 273 198 439 718 138 845 ...
##  $ X2013.1: Factor w/ 1060 levels "0","1,003","1,013",..: 363 863 958 119 275 196 442 734 130 859 ...
##  $ X2014.1: Factor w/ 1071 levels "0","1,006","1,014",..: 378 875 960 121 286 209 457 752 129 874 ...
##  $ X2015.1: Factor w/ 1061 levels "0","1,018","1,025",..: 365 858 943 114 275 196 449 744 116 861 ...
##  $ X2016.1: Factor w/ 1064 levels "0","1,001","1,010",..: 370 859 943 116 283 202 453 752 115 869 ...
##  $ X2017.1: Factor w/ 1058 levels "0","1,016","1,018",..: 379 860 940 112 289 209 454 759 108 904 ...
##  $ X2018.1: Factor w/ 1065 levels "0","1,010","1,018",..: 385 873 951 113 293 210 466 772 106 920 ...
##  $ X2019.1: Factor w/ 1068 levels "0","1,003","1,005,981",..: 392 877 913 113 293 211 473 775 104 925 ...
##  $ X2020.1: Factor w/ 1073 levels "0","1,010","1,013",..: 389 874 903 114 292 206 471 774 100 931 ...
##  $ X1985.2: Factor w/ 1005 levels "0","1,019","1,024",..: 724 292 327 366 156 50 405 546 59 950 ...
##  $ X1986.2: Factor w/ 1014 levels "0","1,029","1,055",..: 815 303 337 376 173 54 418 556 64 961 ...
##  $ X1987.2: Factor w/ 1018 levels "0","1,002","1,053",..: 810 299 337 372 183 51 419 559 70 963 ...
##  $ X1988.2: Factor w/ 1011 levels "0","1,054","1,099",..: 883 303 341 380 191 53 416 560 77 960 ...
##  $ X1989.2: Factor w/ 1013 levels "0","1,011","1,082",..: 887 302 339 374 196 51 423 567 78 963 ...
##  $ X1990.2: Factor w/ 1013 levels "0","1,048","1,165",..: 894 297 341 373 196 51 420 569 80 967 ...
##  $ X1991.2: Factor w/ 1028 levels "0","1,076","1,086",..: 960 291 342 376 197 1024 425 580 86 984 ...
##  $ X1992.2: Factor w/ 1019 levels "0","1,003","1,032",..: 950 282 333 362 185 1012 420 570 81 972 ...
##  $ X1993.2: Factor w/ 1042 levels "0","1,010","1,070",..: 971 283 346 378 199 1032 436 582 89 997 ...
##  $ X1994.2: Factor w/ 1028 levels "0","1,009","1,020",..: 903 277 354 382 202 1017 442 584 97 989 ...
##  $ X1995.2: Factor w/ 1053 levels "0","1,009","1,019",..: 926 270 355 377 208 1038 452 571 96 1014 ...
##  $ X1996.2: Factor w/ 1046 levels "0","1,030","1,046",..: 926 263 352 371 211 1032 461 561 95 1013 ...
##  $ X1997.2: Factor w/ 1057 levels "0","1,042","1,061",..: 858 258 344 356 212 1039 458 554 82 1030 ...
##  $ X1998.2: Factor w/ 1066 levels "0","1,054","1,078",..: 856 259 343 351 211 1050 448 551 88 1036 ...
##  $ X1999.2: Factor w/ 1069 levels "0","1,034","1,054",..: 794 252 346 354 210 1048 452 550 84 1040 ...
##  $ X2000.2: Factor w/ 1074 levels "0","1,062","1,070",..: 789 246 332 338 204 1048 442 539 88 1041 ...
##  $ X2001.2: Factor w/ 1087 levels "0","1,042","1,051",..: 716 247 334 341 205 1062 450 548 94 1063 ...
##  $ X2002.2: Factor w/ 1082 levels "0","1,000","1,021",..: 705 243 59 334 204 1054 444 533 88 1057 ...
##  $ X2003.2: Factor w/ 1083 levels "0","1,005","1,006",..: 710 233 56 64 194 1052 443 528 90 1059 ...
##  $ X2004.2: Factor w/ 1087 levels "0","1,028","1,045",..: 699 221 54 61 190 1058 441 528 87 1066 ...
##  $ X2005.2: Factor w/ 1082 levels "0","1,002","1,010",..: 591 215 54 63 189 1060 436 524 85 1067 ...
##  $ X2006.2: Factor w/ 1092 levels "0","1,006","1,013",..: 596 214 51 63 184 1072 442 531 81 1078 ...
##  $ X2007.2: Factor w/ 1088 levels "0","1,002","1,004",..: 589 204 45 60 177 1064 433 528 73 1070 ...
##   [list output truncated]

1.3 Estadisticas Educación por ETC

data_educacion_raw <- read.csv("educacion.csv")
str(data_educacion_raw)
## 'data.frame':    661 obs. of  37 variables:
##  $ AÑO                        : int  2012 2013 2011 2014 2017 2015 2016 2014 2011 2013 ...
##  $ CÓDIGO_ETC                 : int  3828 3828 3828 3828 3828 3828 3828 3758 3758 3758 ...
##  $ ETC                        : Factor w/ 95 levels "Amazonas (ETC)",..: 1 1 1 1 1 1 1 2 2 2 ...
##  $ POBLACIÓN_5_16             : int  22194 22123 22223 22167 22269 22212 22243 586947 599438 590211 ...
##  $ TASA_MATRICULACIÓN_5_16    : num  8.19e+14 8.18e+01 8.23e+01 8.21e+01 8.36e+01 ...
##  $ COBERTURA_NETA             : num  81.9 81.8 82.3 82.1 82.1 ...
##  $ COBERTURA_NETA_TRANSICIÓN  : num  60.2 48.4 63.7 43.9 49 ...
##  $ COBERTURA_NETA_PRIMARIA    : num  85.6 84 87.2 84.9 80.6 ...
##  $ COBERTURA_NETA_SECUNDARIA  : num  53.3 58.2 50.6 57.7 60.7 ...
##  $ COBERTURA_NETA_MEDIA       : num  22.3 22.1 21.9 23.1 30.1 ...
##  $ COBERTURA_BRUTA            : num  94.8 95.4 94.5 95.7 96.6 ...
##  $ COBERTURA_BRUTA_TRANSICIÓN : num  60.2 96.9 94.5 89.5 92.6 ...
##  $ COBERTURA_BRUTA_PRIMARIA   : num  85.6 111.8 117.8 114 108 ...
##  $ COBERTURA_BRUTA_SECUNDARIA : num  53.3 91.2 82.5 89.1 94.3 ...
##  $ COBERTURA_BRUTA_MEDIA      : num  22.3 59.6 58 63.3 72.2 ...
##  $ TAMAÑO_PROMEDIO_DE_GRUPO   : num  19.3 27.6 14.9 20.3 21 ...
##  $ SEDES_CONECTADAS_A_INTERNET: num  20.9 12.8 36.4 16.5 16.5 ...
##  $ DESERCIÓN                  : num  4.7 3.29 5.46 3.04 4.88 4.76 5.06 2.68 4.16 3.84 ...
##  $ DESERCIÓN_TRANSICIÓN       : num  5.16 3.16 5.56 2.97 6.38 4.54 5.23 2.4 3.89 3.36 ...
##  $ DESERCIÓN_PRIMARIA         : num  2.3 1.82 3.67 1.95 3.06 2.53 2.75 2.26 3.93 3.27 ...
##  $ DESERCIÓN_SECUNDARIA       : num  7.97 5.26 8.21 4.67 6.98 8 8.49 3.55 4.71 5.03 ...
##  $ DESERCIÓN_MEDIA            : num  8.06 5.57 7.9 4.35 6.23 6.69 5.96 2.23 3.87 3.28 ...
##  $ APROBACIÓN                 : num  93.7 95.8 91.2 96.9 87.5 ...
##  $ APROBACIÓN_TRANSICIÓN      : num  94.8 96.8 94.3 97 92.7 ...
##  $ APROBACIÓN_PRIMARIA        : num  95.8 97 92.8 98 90 ...
##  $ APROBACIÓN_SECUNDARIA      : num  90.7 94.2 88.6 95.3 82 ...
##  $ APROBACIÓN_MEDIA           : num  90 92.3 85.2 95.7 86.6 ...
##  $ REPROBACIÓN                : num  1.56 0.93 3.38 0.03 7.67 6.01 5.83 1.02 3.67 5.01 ...
##  $ REPROBACIÓN_TRANSICIÓN     : num  0 0 0.17 0 0.91 0.27 0.32 0.06 0.13 0.17 ...
##  $ REPROBACIÓN_PRIMARIA       : num  1.92 1.13 3.5 0.03 6.91 6.92 5.97 0.84 3.2 4.74 ...
##  $ REPROBACIÓN_SECUNDARIA     : num  1.35 0.56 3.16 0.05 11.01 ...
##  $ REPROBACIÓN_MEDIA          : num  1.98 2.12 6.95 0 7.19 4.79 5.79 1.44 5.69 6.06 ...
##  $ REPITENCIA                 : num  3.9 4.32 1.65 6.3 5.96 5.15 6.61 1.87 2.02 1.7 ...
##  $ REPITENCIA_TRANSICIÓN      : num  0.67 2.46 0.65 2.77 3.3 1.36 1.66 0.19 0.15 0.19 ...
##  $ REPITENCIA_PRIMARIA        : num  3.32 4.41 2.02 6.83 7.06 5.14 7.5 1.77 1.94 1.59 ...
##  $ REPITENCIA_SECUNDARIA      : num  6.17 5.16 1.39 7.25 6.05 6.39 7.17 2.69 2.89 2.44 ...
##  $ REPITENCIA_MEDIA           : num  3.39 2.58 1.34 3.17 2.42 4.15 4.14 1.09 1.24 1.19 ...

1.4 Incautacón Armas de Fuego

data_incauta_raw <- read.csv("Incautafuego_2017.csv")
str(data_incauta_raw)
## 'data.frame':    20508 obs. of  10 variables:
##  $ FECHA         : Factor w/ 365 levels "01/01/2017","01/02/2017",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ DEPARTAMENTO  : Factor w/ 32 levels "AMAZONAS","ANTIOQUIA",..: 1 2 2 2 2 5 5 5 5 5 ...
##  $ MUNICIPIO     : Factor w/ 978 levels "ABEJORRAL","ABREGO",..: 447 38 310 766 827 511 511 511 511 511 ...
##  $ DÍA           : Factor w/ 7 levels "Domingo","Jueves",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ CLASE.DE.ARMA : Factor w/ 11 levels "AMETRALLADORA",..: 10 10 10 9 3 2 5 7 9 10 ...
##  $ PERMISO       : Factor w/ 2 levels "CON PERMISO",..: 1 2 2 2 1 2 2 2 2 2 ...
##  $ ZONA          : Factor w/ 2 levels "RURAL","URBANA": 1 2 1 1 1 1 1 1 1 1 ...
##  $ CLASE.DE.SITIO: Factor w/ 128 levels "AEROPUERTO","ALCALDIA",..: 127 127 127 50 50 128 128 128 128 128 ...
##  $ CÓDIGO.DANE   : int  91001000 5040000 5282000 5674000 5761000 13458000 13458000 13458000 13458000 13458000 ...
##  $ CANTIDAD      : int  1 1 1 1 1 1 13 1 3 2 ...
head(data_incauta_raw)
##        FECHA DEPARTAMENTO    MUNICIPIO     DÍA CLASE.DE.ARMA     PERMISO
## 1 01/01/2017     AMAZONAS LETICIA (CT) Domingo      REVOLVER CON PERMISO
## 2 01/01/2017    ANTIOQUIA        ANORÍ Domingo      REVOLVER SIN PERMISO
## 3 01/01/2017    ANTIOQUIA     FREDONIA Domingo      REVOLVER SIN PERMISO
## 4 01/01/2017    ANTIOQUIA  SAN VICENTE Domingo       PISTOLA SIN PERMISO
## 5 01/01/2017    ANTIOQUIA     SOPETRÁN Domingo      ESCOPETA CON PERMISO
## 6 01/01/2017      BOLÍVAR  MONTECRISTO Domingo      CARABINA SIN PERMISO
##     ZONA     CLASE.DE.SITIO CÓDIGO.DANE CANTIDAD
## 1  RURAL      VIAS PUBLICAS    91001000        1
## 2 URBANA      VIAS PUBLICAS     5040000        1
## 3  RURAL      VIAS PUBLICAS     5282000        1
## 4  RURAL FINCAS Y SIMILARES     5674000        1
## 5  RURAL FINCAS Y SIMILARES     5761000        1
## 6  RURAL     ZONA SELVÁTICA    13458000        1

2 Limpieza

Limpiaremos los dataset.

2.1 Hurto 2017

Se eliminan las columnas:

  • Fecha
  • Hora
  • Barrio
  • País.de.nacimiento
  • Profesión
  • Código.DANE
  • Cantidad
removable_columns <- c("Fecha", "Hora", "Barrio", "País.de.nacimiento", "Profesión", "Código.DANE", "Cantidad")

data_hurto_tidy <- data_hurto_raw[, -which(colnames(data_hurto_raw) %in% removable_columns)]

str(data_hurto_tidy)
## 'data.frame':    185105 obs. of  13 variables:
##  $ Departamento     : Factor w/ 32 levels "AMAZONAS","ANTIOQUIA",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ Municipio        : Factor w/ 901 levels "ABEJORRAL","ABREGO",..: 443 443 443 443 443 443 443 443 443 443 ...
##  $ Día              : Factor w/ 7 levels "Domingo","Jueves",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Zona             : Factor w/ 3 levels "OTRAS","RURAL",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ Clase.de.sitio   : Factor w/ 384 levels "-","AEROPUERTO",..: 382 382 382 382 382 382 382 382 382 84 ...
##  $ Arma.empleada    : Factor w/ 16 levels "-","ALUCINOGENOS",..: 3 3 3 14 4 14 14 14 4 14 ...
##  $ Móvil.Agresor    : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 6 12 2 2 2 14 2 ...
##  $ Móvil.Victima    : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 13 13 2 2 2 5 2 ...
##  $ Edad             : int  39 43 26 29 37 87 30 59 35 28 ...
##  $ Sexo             : Factor w/ 3 levels "-","FEMENINO",..: 3 3 2 2 3 3 3 3 3 3 ...
##  $ Estado.civil     : Factor w/ 7 levels "-","CASADO","DIVORCIADO",..: 6 6 5 6 2 2 5 5 6 6 ...
##  $ Clase.de.empleado: Factor w/ 36 levels "-","AFRODESCENDIENTE",..: 17 17 17 17 26 30 26 26 26 17 ...
##  $ Escolaridad      : Factor w/ 8 levels "-","ANALFABETA",..: 5 4 5 5 5 5 5 5 5 5 ...

Normalizamos los nombres de las columnas.

colnames(data_hurto_tidy) <- c("departamento", "municipio", "dia", "zona", "clase_de_sitio", "arma_empleada", "movil_agresor", "movil_victima", "edad", "sexo", "estado_civil", "clase_de_empleado", "escolaridad")

str(data_hurto_tidy)
## 'data.frame':    185105 obs. of  13 variables:
##  $ departamento     : Factor w/ 32 levels "AMAZONAS","ANTIOQUIA",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ municipio        : Factor w/ 901 levels "ABEJORRAL","ABREGO",..: 443 443 443 443 443 443 443 443 443 443 ...
##  $ dia              : Factor w/ 7 levels "Domingo","Jueves",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ zona             : Factor w/ 3 levels "OTRAS","RURAL",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ clase_de_sitio   : Factor w/ 384 levels "-","AEROPUERTO",..: 382 382 382 382 382 382 382 382 382 84 ...
##  $ arma_empleada    : Factor w/ 16 levels "-","ALUCINOGENOS",..: 3 3 3 14 4 14 14 14 4 14 ...
##  $ movil_agresor    : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 6 12 2 2 2 14 2 ...
##  $ movil_victima    : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 13 13 2 2 2 5 2 ...
##  $ edad             : int  39 43 26 29 37 87 30 59 35 28 ...
##  $ sexo             : Factor w/ 3 levels "-","FEMENINO",..: 3 3 2 2 3 3 3 3 3 3 ...
##  $ estado_civil     : Factor w/ 7 levels "-","CASADO","DIVORCIADO",..: 6 6 5 6 2 2 5 5 6 6 ...
##  $ clase_de_empleado: Factor w/ 36 levels "-","AFRODESCENDIENTE",..: 17 17 17 17 26 30 26 26 26 17 ...
##  $ escolaridad      : Factor w/ 8 levels "-","ANALFABETA",..: 5 4 5 5 5 5 5 5 5 5 ...

Se elimina (CT) de los datos en la columna Municipio.

remove_capital <- function(city_factor) {
  city <- as.character(city_factor)
  no_capital <- gsub(" \\(CT\\)", "", city)

  return(no_capital)
}

data_hurto_tidy$municipio <- as.factor(sapply(data_hurto_tidy$municipio, remove_capital))
str(data_hurto_tidy)
## 'data.frame':    185105 obs. of  13 variables:
##  $ departamento     : Factor w/ 32 levels "AMAZONAS","ANTIOQUIA",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ municipio        : Factor w/ 899 levels "ABEJORRAL","ABREGO",..: 442 442 442 442 442 442 442 442 442 442 ...
##  $ dia              : Factor w/ 7 levels "Domingo","Jueves",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ zona             : Factor w/ 3 levels "OTRAS","RURAL",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ clase_de_sitio   : Factor w/ 384 levels "-","AEROPUERTO",..: 382 382 382 382 382 382 382 382 382 84 ...
##  $ arma_empleada    : Factor w/ 16 levels "-","ALUCINOGENOS",..: 3 3 3 14 4 14 14 14 4 14 ...
##  $ movil_agresor    : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 6 12 2 2 2 14 2 ...
##  $ movil_victima    : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 13 13 2 2 2 5 2 ...
##  $ edad             : int  39 43 26 29 37 87 30 59 35 28 ...
##  $ sexo             : Factor w/ 3 levels "-","FEMENINO",..: 3 3 2 2 3 3 3 3 3 3 ...
##  $ estado_civil     : Factor w/ 7 levels "-","CASADO","DIVORCIADO",..: 6 6 5 6 2 2 5 5 6 6 ...
##  $ clase_de_empleado: Factor w/ 36 levels "-","AFRODESCENDIENTE",..: 17 17 17 17 26 30 26 26 26 17 ...
##  $ escolaridad      : Factor w/ 8 levels "-","ANALFABETA",..: 5 4 5 5 5 5 5 5 5 5 ...

Se cambian todos los - por NA y se eliminan las observaciones con por lo menos un NA.

which(names(summary(data_hurto_tidy$clase_de_sitio)) == "-")
## integer(0)
data_hurto <- data_hurto_tidy
data_hurto[data_hurto_tidy == "-"] <- NA
data_hurto <- data_hurto[complete.cases(data_hurto), ]

str(data_hurto)
## 'data.frame':    182418 obs. of  13 variables:
##  $ departamento     : Factor w/ 32 levels "AMAZONAS","ANTIOQUIA",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ municipio        : Factor w/ 899 levels "ABEJORRAL","ABREGO",..: 442 442 442 442 442 442 442 442 442 442 ...
##  $ dia              : Factor w/ 7 levels "Domingo","Jueves",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ zona             : Factor w/ 3 levels "OTRAS","RURAL",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ clase_de_sitio   : Factor w/ 384 levels "-","AEROPUERTO",..: 382 382 382 382 382 382 382 382 382 84 ...
##  $ arma_empleada    : Factor w/ 16 levels "-","ALUCINOGENOS",..: 3 3 3 14 4 14 14 14 4 14 ...
##  $ movil_agresor    : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 6 12 2 2 2 14 2 ...
##  $ movil_victima    : Factor w/ 15 levels "-","A PIE","BICICLETA",..: 2 2 2 13 13 2 2 2 5 2 ...
##  $ edad             : int  39 43 26 29 37 87 30 59 35 28 ...
##  $ sexo             : Factor w/ 3 levels "-","FEMENINO",..: 3 3 2 2 3 3 3 3 3 3 ...
##  $ estado_civil     : Factor w/ 7 levels "-","CASADO","DIVORCIADO",..: 6 6 5 6 2 2 5 5 6 6 ...
##  $ clase_de_empleado: Factor w/ 36 levels "-","AFRODESCENDIENTE",..: 17 17 17 17 26 30 26 26 26 17 ...
##  $ escolaridad      : Factor w/ 8 levels "-","ANALFABETA",..: 5 4 5 5 5 5 5 5 5 5 ...

Se cambia el orden de unos factores.

data_hurto$escolaridad <- factor(data_hurto$escolaridad, levels = c("NO REPORTADO", "ANALFABETA", "PRIMARIA", "SECUNDARIA", "TECNOLOGO", "TECNICO", "SUPERIOR"))

data_hurto$dia <- factor(data_hurto$dia, levels = c("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"))
head(data_hurto)
##   departamento municipio     dia   zona clase_de_sitio
## 1    ANTIOQUIA  MEDELLÍN Domingo URBANA  VIAS PUBLICAS
## 2    ANTIOQUIA  MEDELLÍN Domingo URBANA  VIAS PUBLICAS
## 3    ANTIOQUIA  MEDELLÍN Domingo URBANA  VIAS PUBLICAS
## 4    ANTIOQUIA  MEDELLÍN Domingo URBANA  VIAS PUBLICAS
## 5    ANTIOQUIA  MEDELLÍN Domingo URBANA  VIAS PUBLICAS
## 6    ANTIOQUIA  MEDELLÍN Domingo URBANA  VIAS PUBLICAS
##                 arma_empleada        movil_agresor movil_victima edad
## 1 ARMA BLANCA / CORTOPUNZANTE                A PIE         A PIE   39
## 2 ARMA BLANCA / CORTOPUNZANTE                A PIE         A PIE   43
## 3 ARMA BLANCA / CORTOPUNZANTE                A PIE         A PIE   26
## 4         SIN EMPLEO DE ARMAS       CONDUCTOR TAXI PASAJERO TAXI   29
## 5               ARMA DE FUEGO PASAJERO MOTOCICLETA PASAJERO TAXI   37
## 6         SIN EMPLEO DE ARMAS                A PIE         A PIE   87
##        sexo estado_civil   clase_de_empleado escolaridad
## 1 MASCULINO  UNION LIBRE EMPLEADO PARTICULAR  SECUNDARIA
## 2 MASCULINO  UNION LIBRE EMPLEADO PARTICULAR    PRIMARIA
## 3  FEMENINO      SOLTERO EMPLEADO PARTICULAR  SECUNDARIA
## 4  FEMENINO  UNION LIBRE EMPLEADO PARTICULAR  SECUNDARIA
## 5 MASCULINO       CASADO       INDEPENDIENTE  SECUNDARIA
## 6 MASCULINO       CASADO          PENSIONADO  SECUNDARIA

2.2 Poblacion por municipio

Dejamos:

  • MPIO que es el nombre del municipio
  • X2017 que es la poblacion por municipio en 2017
target_columns <- c("MPIO", "X2017")
data_municipios_tidy <- data_municipios_raw[, which(colnames(data_municipios_raw) %in% target_columns)]

str(data_municipios_tidy)
## 'data.frame':    1123 obs. of  2 variables:
##  $ MPIO : Factor w/ 1041 levels "Abejorral","Abrego",..: 519 1 3 20 30 31 36 37 38 40 ...
##  $ X2017: Factor w/ 1100 levels "1,024,882","1,066",..: 378 327 349 561 542 443 762 1057 79 289 ...

Normalizamos el nombre de cada columna.

colnames(data_municipios_tidy) <- c("municipio", "poblacion_2017")
str(data_municipios_tidy)
## 'data.frame':    1123 obs. of  2 variables:
##  $ municipio     : Factor w/ 1041 levels "Abejorral","Abrego",..: 519 1 3 20 30 31 36 37 38 40 ...
##  $ poblacion_2017: Factor w/ 1100 levels "1,024,882","1,066",..: 378 327 349 561 542 443 762 1057 79 289 ...

Convertimos la columna poblacion_2017 en numerica.

factor_to_int <- function(a_factor) {
  a_char <- as.character(a_factor)
  no_commas <- gsub(",", "", a_char)
  num <- as.integer(no_commas)

  return(num)
}

data_municipios_tidy$poblacion_2017 <- sapply(data_municipios_tidy$poblacion_2017, factor_to_int)
data_municipios_tidy$municipio <- sapply(data_municipios_tidy$municipio, toupper)

str(data_municipios_tidy)
## 'data.frame':    1123 obs. of  2 variables:
##  $ municipio     : chr  "MEDELLÍN" "ABEJORRAL" "ABRIAQUÍ" "ALEJANDRÍA" ...
##  $ poblacion_2017: int  2508452 19096 2019 3393 29980 22414 46621 9216 11139 17521 ...

Eliminamos la fila que tiene el total nacional.

data_municipios_tidy <- data_municipios_tidy[data_municipios_tidy$municipio != "TOTAL NACIONAL", ]

str(data_municipios_tidy)
## 'data.frame':    1122 obs. of  2 variables:
##  $ municipio     : chr  "MEDELLÍN" "ABEJORRAL" "ABRIAQUÍ" "ALEJANDRÍA" ...
##  $ poblacion_2017: int  2508452 19096 2019 3393 29980 22414 46621 9216 11139 17521 ...

Eliminar la coma de BOGOTA, D.C.

bogota_row <- data_municipios_tidy[data_municipios_tidy$municipio == "BOGOTÁ, D.C.", ]
bogota_row$municipio <- c("BOGOTÁ D.C.")

data_municipios_tidy[data_municipios_tidy$municipio == "BOGOTÁ, D.C.", ] <- bogota_row

data_municipios <- data_municipios_tidy

2.3 Educacion

Eliminamos la columna CÓDIGO_ETC.

data_educacion_tidy <- data_educacion_raw

data_educacion_tidy <- data_educacion_tidy[, -which(colnames(data_educacion_tidy) == "CÓDIGO_ETC")]
str(data_educacion_tidy)
## 'data.frame':    661 obs. of  36 variables:
##  $ AÑO                        : int  2012 2013 2011 2014 2017 2015 2016 2014 2011 2013 ...
##  $ ETC                        : Factor w/ 95 levels "Amazonas (ETC)",..: 1 1 1 1 1 1 1 2 2 2 ...
##  $ POBLACIÓN_5_16             : int  22194 22123 22223 22167 22269 22212 22243 586947 599438 590211 ...
##  $ TASA_MATRICULACIÓN_5_16    : num  8.19e+14 8.18e+01 8.23e+01 8.21e+01 8.36e+01 ...
##  $ COBERTURA_NETA             : num  81.9 81.8 82.3 82.1 82.1 ...
##  $ COBERTURA_NETA_TRANSICIÓN  : num  60.2 48.4 63.7 43.9 49 ...
##  $ COBERTURA_NETA_PRIMARIA    : num  85.6 84 87.2 84.9 80.6 ...
##  $ COBERTURA_NETA_SECUNDARIA  : num  53.3 58.2 50.6 57.7 60.7 ...
##  $ COBERTURA_NETA_MEDIA       : num  22.3 22.1 21.9 23.1 30.1 ...
##  $ COBERTURA_BRUTA            : num  94.8 95.4 94.5 95.7 96.6 ...
##  $ COBERTURA_BRUTA_TRANSICIÓN : num  60.2 96.9 94.5 89.5 92.6 ...
##  $ COBERTURA_BRUTA_PRIMARIA   : num  85.6 111.8 117.8 114 108 ...
##  $ COBERTURA_BRUTA_SECUNDARIA : num  53.3 91.2 82.5 89.1 94.3 ...
##  $ COBERTURA_BRUTA_MEDIA      : num  22.3 59.6 58 63.3 72.2 ...
##  $ TAMAÑO_PROMEDIO_DE_GRUPO   : num  19.3 27.6 14.9 20.3 21 ...
##  $ SEDES_CONECTADAS_A_INTERNET: num  20.9 12.8 36.4 16.5 16.5 ...
##  $ DESERCIÓN                  : num  4.7 3.29 5.46 3.04 4.88 4.76 5.06 2.68 4.16 3.84 ...
##  $ DESERCIÓN_TRANSICIÓN       : num  5.16 3.16 5.56 2.97 6.38 4.54 5.23 2.4 3.89 3.36 ...
##  $ DESERCIÓN_PRIMARIA         : num  2.3 1.82 3.67 1.95 3.06 2.53 2.75 2.26 3.93 3.27 ...
##  $ DESERCIÓN_SECUNDARIA       : num  7.97 5.26 8.21 4.67 6.98 8 8.49 3.55 4.71 5.03 ...
##  $ DESERCIÓN_MEDIA            : num  8.06 5.57 7.9 4.35 6.23 6.69 5.96 2.23 3.87 3.28 ...
##  $ APROBACIÓN                 : num  93.7 95.8 91.2 96.9 87.5 ...
##  $ APROBACIÓN_TRANSICIÓN      : num  94.8 96.8 94.3 97 92.7 ...
##  $ APROBACIÓN_PRIMARIA        : num  95.8 97 92.8 98 90 ...
##  $ APROBACIÓN_SECUNDARIA      : num  90.7 94.2 88.6 95.3 82 ...
##  $ APROBACIÓN_MEDIA           : num  90 92.3 85.2 95.7 86.6 ...
##  $ REPROBACIÓN                : num  1.56 0.93 3.38 0.03 7.67 6.01 5.83 1.02 3.67 5.01 ...
##  $ REPROBACIÓN_TRANSICIÓN     : num  0 0 0.17 0 0.91 0.27 0.32 0.06 0.13 0.17 ...
##  $ REPROBACIÓN_PRIMARIA       : num  1.92 1.13 3.5 0.03 6.91 6.92 5.97 0.84 3.2 4.74 ...
##  $ REPROBACIÓN_SECUNDARIA     : num  1.35 0.56 3.16 0.05 11.01 ...
##  $ REPROBACIÓN_MEDIA          : num  1.98 2.12 6.95 0 7.19 4.79 5.79 1.44 5.69 6.06 ...
##  $ REPITENCIA                 : num  3.9 4.32 1.65 6.3 5.96 5.15 6.61 1.87 2.02 1.7 ...
##  $ REPITENCIA_TRANSICIÓN      : num  0.67 2.46 0.65 2.77 3.3 1.36 1.66 0.19 0.15 0.19 ...
##  $ REPITENCIA_PRIMARIA        : num  3.32 4.41 2.02 6.83 7.06 5.14 7.5 1.77 1.94 1.59 ...
##  $ REPITENCIA_SECUNDARIA      : num  6.17 5.16 1.39 7.25 6.05 6.39 7.17 2.69 2.89 2.44 ...
##  $ REPITENCIA_MEDIA           : num  3.39 2.58 1.34 3.17 2.42 4.15 4.14 1.09 1.24 1.19 ...

Normalizamos los nombres de las columnas.

colnames(data_educacion_tidy) <- sapply(colnames(data_educacion_tidy), tolower)

Conservamos solo el año 2017 y posteriormente eliminamos la columna.

data_educacion_tidy <- data_educacion_tidy[data_educacion_tidy$año == 2017, ]
data_educacion_tidy <- data_educacion_tidy[, -which(colnames(data_educacion_tidy) == "año")]

str(data_educacion_tidy)
## 'data.frame':    95 obs. of  35 variables:
##  $ etc                        : Factor w/ 95 levels "Amazonas (ETC)",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ población_5_16             : int  22269 588225 49431 75197 15106 54421 112847 37581 237521 93422 ...
##  $ tasa_matriculación_5_16    : num  83.6 82.4 59 75 67.8 ...
##  $ cobertura_neta             : num  82.1 82.3 59 75 67.6 ...
##  $ cobertura_neta_transición  : num  49 51.2 33 47.3 51.2 ...
##  $ cobertura_neta_primaria    : num  80.6 79.7 55.6 74 67.8 ...
##  $ cobertura_neta_secundaria  : num  60.7 68.3 52.2 58.4 59.7 ...
##  $ cobertura_neta_media       : num  30.1 36.7 26.6 30.9 37.8 ...
##  $ cobertura_bruta            : num  96.6 93.4 71.1 86.6 72.4 ...
##  $ cobertura_bruta_transición : num  92.6 71.9 51.3 83.2 67.1 ...
##  $ cobertura_bruta_primaria   : num  108 102 72.4 97 77.7 ...
##  $ cobertura_bruta_secundaria : num  94.3 99.7 82.9 85.6 75.6 ...
##  $ cobertura_bruta_media      : num  72.2 69.5 55.3 62.2 55.6 ...
##  $ tamaño_promedio_de_grupo   : num  21 29.5 35.8 21.8 27.4 ...
##  $ sedes_conectadas_a_internet: num  16.5 22.8 46.9 35.8 79.2 ...
##  $ deserción                  : num  4.88 4.9 4.99 3.63 1.15 4.41 1.59 2 1.14 3.06 ...
##  $ deserción_transición       : num  6.38 4.11 3.3 3.9 0.75 4.53 2.37 2.96 1.84 2.94 ...
##  $ deserción_primaria         : num  3.06 3.87 3.52 3.28 1.29 3.02 1.51 1.54 1.05 2.71 ...
##  $ deserción_secundaria       : num  6.98 6.76 7.65 4.23 1.13 5.91 1.63 2.38 1.21 3.82 ...
##  $ deserción_media            : num  6.23 4.19 3.88 3.21 0.9 4.3 1.31 1.94 0.86 2.14 ...
##  $ aprobación                 : num  87.5 90 85 96.3 97.9 ...
##  $ aprobación_transición      : num  92.7 95.7 96.1 96.1 99.2 ...
##  $ aprobación_primaria        : num  90 91.3 88.1 96.7 98.1 ...
##  $ aprobación_secundaria      : num  82 86.5 77.4 95.8 97 ...
##  $ aprobación_media           : num  86.6 91 88.7 96.1 98.6 ...
##  $ reprobación                : num  7.67 5.12 10.02 0.07 0.97 ...
##  $ reprobación_transición     : num  0.91 0.16 0.62 NA NA 0.25 0.29 0.98 1.84 0.36 ...
##  $ reprobación_primaria       : num  6.91 4.8 8.41 NA 0.62 4.47 5.9 7.18 3.39 0.83 ...
##  $ reprobación_secundaria     : num  11.01 6.72 14.94 NA 1.82 ...
##  $ reprobación_media          : num  7.19 4.8 7.39 0.73 0.5 6.31 4.08 9.65 2.75 0.83 ...
##  $ repitencia                 : num  5.96 5.44 0.61 7.17 2.04 0.74 1.4 5.27 1.28 1.45 ...
##  $ repitencia_transición      : num  3.3 1.26 0.1 5.85 1.34 0.04 0.53 1.35 1.36 0.25 ...
##  $ repitencia_primaria        : num  7.06 6.1 0.4 6.85 1.22 0.53 1.59 3.62 1.42 1.48 ...
##  $ repitencia_secundaria      : num  6.05 6.38 1.1 9.05 3.75 1.24 1.67 8.86 1.44 1.96 ...
##  $ repitencia_media           : num  2.42 1.96 0.26 3.68 0.8 0.35 0.53 3.64 0.35 0.41 ...

Transformamos las ETC en mayuscula y removemos el (ETC).

remove_etc <- function(city_factor) {
  city <- as.character(city_factor)
  no_capital <- gsub(" \\(ETC\\)", "", city)

  return(no_capital)
}

data_educacion_tidy$etc <- sapply(data_educacion_tidy$etc, toupper)
data_educacion_tidy$etc <- sapply(data_educacion_tidy$etc, remove_etc)
data_educacion_tidy$etc <- sapply(data_educacion_tidy$etc, remove_capital)

data_educacion <- data_educacion_tidy

2.4 Limpieza Dataset sobre armas incautadas en 2017

Este data set cuenta con variables que no aportan para nuestro analisis tales como: * Fecha * Hora * Permiso * Código.DANE * Cantidad

Ya que estas representan códigos de numeraciòn o tienen solo un valor asignado.

removable_columns_2 <- c("FECHA", "HORA", "PERMISO", "CÓDIGO.DANE", "CANTIDAD")

data_incauta_tidy <- data_incauta_raw[,-which(colnames(data_incauta_raw) %in% removable_columns_2)]

str(data_incauta_tidy)
## 'data.frame':    20508 obs. of  6 variables:
##  $ DEPARTAMENTO  : Factor w/ 32 levels "AMAZONAS","ANTIOQUIA",..: 1 2 2 2 2 5 5 5 5 5 ...
##  $ MUNICIPIO     : Factor w/ 978 levels "ABEJORRAL","ABREGO",..: 447 38 310 766 827 511 511 511 511 511 ...
##  $ DÍA           : Factor w/ 7 levels "Domingo","Jueves",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ CLASE.DE.ARMA : Factor w/ 11 levels "AMETRALLADORA",..: 10 10 10 9 3 2 5 7 9 10 ...
##  $ ZONA          : Factor w/ 2 levels "RURAL","URBANA": 1 2 1 1 1 1 1 1 1 1 ...
##  $ CLASE.DE.SITIO: Factor w/ 128 levels "AEROPUERTO","ALCALDIA",..: 127 127 127 50 50 128 128 128 128 128 ...

Normalizamos los nombres de las columnas.

colnames(data_incauta_tidy) <- c("departamento", "municipio", "dia","clase_de_arma", "zona", "clase_de_sitio")
str(data_incauta_tidy)
## 'data.frame':    20508 obs. of  6 variables:
##  $ departamento  : Factor w/ 32 levels "AMAZONAS","ANTIOQUIA",..: 1 2 2 2 2 5 5 5 5 5 ...
##  $ municipio     : Factor w/ 978 levels "ABEJORRAL","ABREGO",..: 447 38 310 766 827 511 511 511 511 511 ...
##  $ dia           : Factor w/ 7 levels "Domingo","Jueves",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ clase_de_arma : Factor w/ 11 levels "AMETRALLADORA",..: 10 10 10 9 3 2 5 7 9 10 ...
##  $ zona          : Factor w/ 2 levels "RURAL","URBANA": 1 2 1 1 1 1 1 1 1 1 ...
##  $ clase_de_sitio: Factor w/ 128 levels "AEROPUERTO","ALCALDIA",..: 127 127 127 50 50 128 128 128 128 128 ...

3 Pre-procesamiento

Calculamos indice de hurtos por municipio.

hurtos_per_muni <- data_hurto %>%
  group_by(municipio) %>%
  summarize(
    cantidad_hurtos = n()
  )

muni_joined <- data_municipios %>%
  left_join(hurtos_per_muni, by = c("municipio" = "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
attach(muni_joined)
muni_joined$indice_hurtos <- (cantidad_hurtos / poblacion_2017) * 1000
detach(muni_joined)

muni_joined_sorted <- muni_joined[order(-muni_joined$poblacion_2017), ]

sum(is.na(muni_joined$cantidad_hurtos))
## [1] 155

Visualizamos los 30 primeros municipios en indice de hurtos.

muni_top <- head(muni_joined_sorted, 30)
muni_top_sorted <- muni_top[order(-muni_top$indice_hurtos), ]
muni_top_sorted
##                 municipio poblacion_2017 cantidad_hurtos indice_hurtos
## 716                 PASTO         450645            4460     9.8969255
## 362               POPAYÁN         282453            2342     8.2916450
## 149           BOGOTÁ D.C.        8080734           64188     7.9433378
## 846           BUCARAMANGA         528497            4068     7.6973001
## 1                MEDELLÍN        2508452           17522     6.9851845
## 687         VILLAVICENCIO         506012            3514     6.9444993
## 605                 NEIVA         345806            2296     6.6395609
## 1006                 CALI        2420114           14681     6.0662432
## 832               PEREIRA         474335            2701     5.6942878
## 959                IBAGUÉ         564076            3010     5.3361604
## 820               ARMENIA         299712            1518     5.0648623
## 47               ENVIGADO         232903            1177     5.0536060
## 319             MANIZALES         398830            1883     4.7213098
## 933             SINCELEJO         282868            1327     4.6912341
## 657           SANTA MARTA         499391            2329     4.6636804
## 126          BARRANQUILLA        1228271            5585     4.5470421
## 878         FLORIDABLANCA         266617            1211     4.5420960
## 59                 ITAGUI         273927            1164     4.2493073
## 1032              PALMIRA         308669            1140     3.6932766
## 780                CÚCUTA         662673            2267     3.4209935
## 19                  BELLO         473423            1594     3.3669678
## 404            VALLEDUPAR         473251            1554     3.2836698
## 429              MONTERÍA         453931            1437     3.1656794
## 545                SOACHA         533718            1309     2.4526061
## 642              RIOHACHA         277868             625     2.2492694
## 1041                TULUÁ         216619             470     2.1697081
## 150             CARTAGENA        1024882            1954     1.9065610
## 145               SOLEDAD         649111            1079     1.6622735
## 1012         BUENAVENTURA         415770             637     1.5320971
## 777  SAN ANDRES DE TUMACO         208318             108     0.5184382

Añadimos la información del dataset de educación.

edu_joined <- muni_joined %>%
  left_join(data_educacion, by = c("municipio" = "etc"), copy = TRUE)

str(edu_joined)
## 'data.frame':    1122 obs. of  38 variables:
##  $ municipio                  : chr  "MEDELLÍN" "ABEJORRAL" "ABRIAQUÍ" "ALEJANDRÍA" ...
##  $ poblacion_2017             : int  2508452 19096 2019 3393 29980 22414 46621 9216 11139 17521 ...
##  $ cantidad_hurtos            : int  17522 16 2 1 28 27 33 6 2 17 ...
##  $ indice_hurtos              : num  6.985 0.838 0.991 0.295 0.934 ...
##  $ población_5_16             : int  370202 NA NA NA NA NA NA NA NA NA ...
##  $ tasa_matriculación_5_16    : num  101 NA NA NA NA ...
##  $ cobertura_neta             : num  101 NA NA NA NA ...
##  $ cobertura_neta_transición  : num  73.1 NA NA NA NA ...
##  $ cobertura_neta_primaria    : num  98.6 NA NA NA NA ...
##  $ cobertura_neta_secundaria  : num  89.9 NA NA NA NA ...
##  $ cobertura_neta_media       : num  54.9 NA NA NA NA ...
##  $ cobertura_bruta            : num  116 NA NA NA NA ...
##  $ cobertura_bruta_transición : num  88.5 NA NA NA NA ...
##  $ cobertura_bruta_primaria   : num  114 NA NA NA NA ...
##  $ cobertura_bruta_secundaria : num  130 NA NA NA NA ...
##  $ cobertura_bruta_media      : num  108 NA NA NA NA ...
##  $ tamaño_promedio_de_grupo   : num  34 NA NA NA NA ...
##  $ sedes_conectadas_a_internet: num  98.3 NA NA NA NA ...
##  $ deserción                  : num  3.46 NA NA NA NA NA NA NA NA NA ...
##  $ deserción_transición       : num  3.05 NA NA NA NA NA NA NA NA NA ...
##  $ deserción_primaria         : num  2.71 NA NA NA NA NA NA NA NA NA ...
##  $ deserción_secundaria       : num  4.68 NA NA NA NA NA NA NA NA NA ...
##  $ deserción_media            : num  2.8 NA NA NA NA NA NA NA NA NA ...
##  $ aprobación                 : num  85.3 NA NA NA NA ...
##  $ aprobación_transición      : num  96.8 NA NA NA NA NA NA NA NA NA ...
##  $ aprobación_primaria        : num  88.6 NA NA NA NA ...
##  $ aprobación_secundaria      : num  77.8 NA NA NA NA ...
##  $ aprobación_media           : num  89.6 NA NA NA NA ...
##  $ reprobación                : num  11.2 NA NA NA NA ...
##  $ reprobación_transición     : num  0.15 NA NA NA NA NA NA NA NA NA ...
##  $ reprobación_primaria       : num  8.7 NA NA NA NA NA NA NA NA NA ...
##  $ reprobación_secundaria     : num  17.5 NA NA NA NA ...
##  $ reprobación_media          : num  7.57 NA NA NA NA NA NA NA NA NA ...
##  $ repitencia                 : num  10.2 NA NA NA NA ...
##  $ repitencia_transición      : num  1.37 NA NA NA NA NA NA NA NA NA ...
##  $ repitencia_primaria        : num  8.96 NA NA NA NA NA NA NA NA NA ...
##  $ repitencia_secundaria      : num  15 NA NA NA NA ...
##  $ repitencia_media           : num  4.83 NA NA NA NA NA NA NA NA NA ...

Removemos las filas con NA y con indice de hurto mayor a 10.

edu_joined <- edu_joined[complete.cases(edu_joined), ] %>% filter(indice_hurtos <= 10)
str(edu_joined)
## 'data.frame':    59 obs. of  38 variables:
##  $ municipio                  : chr  "MEDELLÍN" "BELLO" "CALDAS" "NARIÑO" ...
##  $ poblacion_2017             : int  2508452 473423 79652 17686 124219 1228271 649111 1024882 12342 123906 ...
##  $ cantidad_hurtos            : int  17522 1594 141 9 654 5585 1079 1954 14 160 ...
##  $ indice_hurtos              : num  6.985 3.367 1.77 0.509 5.265 ...
##  $ población_5_16             : int  370202 93422 125643 223685 24795 237521 140244 210840 267545 28640 ...
##  $ tasa_matriculación_5_16    : num  101.3 78.5 73.6 63.5 82.8 ...
##  $ cobertura_neta             : num  101.2 78.5 73.5 63.5 82.5 ...
##  $ cobertura_neta_transición  : num  73.1 53.4 48.6 33 57 ...
##  $ cobertura_neta_primaria    : num  98.6 77.2 67.7 59.3 76.6 ...
##  $ cobertura_neta_secundaria  : num  89.9 67.3 65.1 50.5 74 ...
##  $ cobertura_neta_media       : num  54.9 38.3 40.5 25.5 46.3 ...
##  $ cobertura_bruta            : num  116.3 89.8 84.3 76.2 94 ...
##  $ cobertura_bruta_transición : num  88.5 65.6 61.1 60.1 70.9 ...
##  $ cobertura_bruta_primaria   : num  114 91.3 84.8 85.4 90.2 ...
##  $ cobertura_bruta_secundaria : num  130.2 101.8 93.4 78.9 106.5 ...
##  $ cobertura_bruta_media      : num  107.6 74.4 75.9 56.1 89.3 ...
##  $ tamaño_promedio_de_grupo   : num  34 34.5 26.5 17 31.1 ...
##  $ sedes_conectadas_a_internet: num  98.3 93.7 31.2 21.6 100 ...
##  $ deserción                  : num  3.46 3.06 3.73 1.52 3.92 1.14 1.22 2.77 3.1 3.31 ...
##  $ deserción_transición       : num  3.05 2.94 3.8 1.18 2.38 1.84 1.9 4.26 2.93 6.62 ...
##  $ deserción_primaria         : num  2.71 2.71 2.85 1.03 2.41 1.05 1.24 2.33 2.11 2.82 ...
##  $ deserción_secundaria       : num  4.68 3.82 4.95 2.06 6.06 1.21 1.23 3.1 4.33 3.49 ...
##  $ deserción_media            : num  2.8 2.14 3.28 2.15 3.38 0.86 0.74 2.51 3.9 2.12 ...
##  $ aprobación                 : num  85.3 96.1 88.6 97.4 80.2 ...
##  $ aprobación_transición      : num  96.8 96.7 95.8 98.3 97 ...
##  $ aprobación_primaria        : num  88.6 96.5 91 97.9 86.1 ...
##  $ aprobación_secundaria      : num  77.8 95.3 83.8 96.7 69.3 ...
##  $ aprobación_media           : num  89.6 97 90.4 97.1 85 ...
##  $ reprobación                : num  11.23 0.84 7.64 1.06 15.87 ...
##  $ reprobación_transición     : num  0.15 0.36 0.37 0.48 0.62 1.84 0.77 0.41 0.12 0.52 ...
##  $ reprobación_primaria       : num  8.7 0.83 6.14 1.11 11.53 ...
##  $ reprobación_secundaria     : num  17.51 0.92 11.23 1.21 24.61 ...
##  $ reprobación_media          : num  7.57 0.83 6.36 0.73 11.64 ...
##  $ repitencia                 : num  10.16 1.45 2.08 2.61 11.91 ...
##  $ repitencia_transición      : num  1.37 0.25 0.28 0.9 1.76 1.36 0.47 7.78 1.91 3.05 ...
##  $ repitencia_primaria        : num  8.96 1.48 1.64 2.3 9.87 1.42 0.35 7.35 2.98 3.4 ...
##  $ repitencia_secundaria      : num  14.98 1.96 3.32 3.75 17.17 ...
##  $ repitencia_media           : num  4.83 0.41 0.98 1.46 7.9 0.35 0.2 3.82 1.63 1.86 ...

4 Analisis Univariado

4.1 Hurtos

columns_f <- c("edad", "escolaridad", "dia", "municipio", "movil_agresor", "clase_de_empleado", "estado_civil")

data_hurto_f <- data_hurto[, colnames(data_hurto) %in% columns_f]

summary(data_hurto_f)
##         municipio            dia                      movil_agresor   
##  BOGOTÁ D.C. :64188   Domingo  :19820   A PIE                :130512  
##  MEDELLÍN    :17522   Lunes    :23454   PASAJERO MOTOCICLETA : 20200  
##  CALI        :14681   Martes   :27086   CONDUCTOR MOTOCICLETA: 13051  
##  BARRANQUILLA: 5585   Miércoles:27433   PASAJERO BUS         :  7516  
##  PASTO       : 4460   Jueves   :27603   BICICLETA            :  4533  
##  BUCARAMANGA : 4068   Viernes  :28914   CONDUCTOR VEHICULO   :  1773  
##  (Other)     :71914   Sábado   :28108   (Other)              :  4833  
##       edad             estado_civil             clase_de_empleado 
##  Min.   :  0.00   -          :    0   EMPLEADO PARTICULAR:105331  
##  1st Qu.: 25.00   CASADO     :37575   INDEPENDIENTE      : 31676  
##  Median : 33.00   DIVORCIADO : 3041   ESTUDIANTE         : 14312  
##  Mean   : 35.17   SEPARADO   : 2605   AMA DE CASA        :  6852  
##  3rd Qu.: 43.00   SOLTERO    :96804   COMERCIANTE        :  6747  
##  Max.   :450.00   UNION LIBRE:40385   EMPLEADO PUBLICO   :  3644  
##                   VIUDO      : 2008   (Other)            : 13856  
##        escolaridad   
##  NO REPORTADO: 1246  
##  ANALFABETA  :  237  
##  PRIMARIA    :26578  
##  SECUNDARIA  :85978  
##  TECNOLOGO   : 5948  
##  TECNICO     :14530  
##  SUPERIOR    :47901
columns_f_l <- c("municipio","departamento", "zona", "dia", "clase_de_sitio", "arma_empleada", "movil_victima", "sexo")
data_hurto_f_l <- data_hurto[, colnames(data_hurto) %in% columns_f_l]

summary(data_hurto_f_l)
##        departamento          municipio            dia       
##  CUNDINAMARCA:68946   BOGOTÁ D.C. :64188   Domingo  :19820  
##  ANTIOQUIA   :25853   MEDELLÍN    :17522   Lunes    :23454  
##  VALLE       :19662   CALI        :14681   Martes   :27086  
##  SANTANDER   : 8242   BARRANQUILLA: 5585   Miércoles:27433  
##  ATLÁNTICO   : 7220   PASTO       : 4460   Jueves   :27603  
##  NARIÑO      : 5610   BUCARAMANGA : 4068   Viernes  :28914  
##  (Other)     :46885   (Other)     :71914   Sábado   :28108  
##      zona                                   clase_de_sitio  
##  OTRAS :    11   VIAS PUBLICAS                     :108706  
##  RURAL :  9534   CASAS DE HABITACION               :  5522  
##  URBANA:172873   FRENTE A RESIDENCIAS - VIA PUBLICA:  3064  
##                  CARRETERA                         :  2595  
##                  LOCAL COMERCIAL                   :  2523  
##                  CALLEJÓN                          :  2435  
##                  (Other)                           : 57573  
##                      arma_empleada                 movil_victima   
##  SIN EMPLEO DE ARMAS        :87924   A PIE                :141171  
##  ARMA BLANCA / CORTOPUNZANTE:43135   CONDUCTOR VEHICULO   : 12248  
##  ARMA DE FUEGO              :35329   PASAJERO BUS         : 10134  
##  CONTUNDENTES               :13833   CONDUCTOR MOTOCICLETA:  6384  
##  ESCOPOLAMINA               : 1862   BICICLETA            :  4262  
##  NO REPORTADO               :  160   PASAJERO VEHICULO    :  1993  
##  (Other)                    :  175   (Other)              :  6226  
##         sexo       
##  -        :     0  
##  FEMENINO : 77497  
##  MASCULINO:104921  
##                    
##                    
##                    
## 

Se utilizara la siguiente funcion para graficar los factores del data set.

plot_factor <- function(data, column, top = 30) {
  group_count <- data %>%
    group_by_(column) %>%
    summarise(
      cantidad_hurtos = n()
    ) %>%
    arrange(desc(cantidad_hurtos)) %>%
    top_n(top)

  ggplot(group_count) +
    geom_bar(
      aes_string(x = paste0("reorder(", column, ", cantidad_hurtos)"), y = "cantidad_hurtos"),
      stat = "identity"
    ) +
    coord_flip() +
    labs(x = column, y = "Cantidad de hurtos reportados") +
    theme(axis.text.y = element_text(size = (rel(0.8))))
}

4.1.1 Municipio

plot_factor(data_hurto_f, "municipio", 20)
## Selecting by cantidad_hurtos

4.1.2 Día

plot_factor(data_hurto_f, "dia")
## Selecting by cantidad_hurtos

4.1.3 Móvil Agresor

plot_factor(data_hurto_f, "movil_agresor", 20)
## Selecting by cantidad_hurtos

4.1.4 Estado Civil

plot_factor(data_hurto_f, "estado_civil")
## Selecting by cantidad_hurtos

4.1.5 Clase de Empleado

plot_factor(data_hurto_f, "clase_de_empleado", 20)
## Selecting by cantidad_hurtos

4.1.6 Escolaridad

plot_factor(data_hurto_f, "escolaridad")
## Selecting by cantidad_hurtos

4.1.7 Edad

edad_count <- data_hurto_f %>%
  group_by(edad) %>%
  summarise(
    cantidad_hurtos = n()
  )

ggplot(edad_count) +
  geom_point(aes(x = edad, y = cantidad_hurtos))

Existen unos datos atipicos de edades mayores a 100, los eliminamos par visualizar la distribucion resultante.

edad_count_fix <- edad_count %>%
  filter(edad < 100)

ggplot(edad_count_fix) +
  geom_point(aes(x = edad, y = cantidad_hurtos))

4.1.8 Municipio

plot_factor(data_hurto_f_l, "municipio", 20)
## Selecting by cantidad_hurtos

4.1.9 Departamentos

plot_factor(data_hurto_f_l, "departamento", 20)
## Selecting by cantidad_hurtos

4.1.10 Zona

plot_factor(data_hurto_f_l, "zona", 20)
## Selecting by cantidad_hurtos

4.1.11 Clase de sitio

plot_factor(data_hurto_f_l, "clase_de_sitio", 20)
## Selecting by cantidad_hurtos

4.1.12 Arma empleada

plot_factor(data_hurto_f_l, "arma_empleada", 20)
## Selecting by cantidad_hurtos

4.1.13 Movil Víctima

plot_factor(data_hurto_f_l, "movil_victima", 20)
## Selecting by cantidad_hurtos

4.1.14 Sexo

plot_factor(data_hurto_f_l, "sexo", 20)
## Selecting by cantidad_hurtos

4.2 Educación

4.2.1 Población entre 5 y 16 años

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, población_5_16), y = población_5_16)) +
  coord_flip()

4.2.2 Tasa matriculacion entre 5 y 16 años

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, tasa_matriculación_5_16), y = tasa_matriculación_5_16)) +
  coord_flip()

4.2.3 Cobertura neta

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, cobertura_neta), y = cobertura_neta)) +
  coord_flip()

4.2.4 Cobertura bruta

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, cobertura_bruta), y = cobertura_bruta)) +
  coord_flip()

4.2.5 Tamaño promedio de grupo

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, tamaño_promedio_de_grupo), y = tamaño_promedio_de_grupo)) +
  coord_flip()

4.2.6 Sedes conectadas a internet

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, sedes_conectadas_a_internet), y = sedes_conectadas_a_internet)) +
  coord_flip()

4.2.7 Deserción

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, deserción), y = deserción)) +
  coord_flip()

4.2.8 Aprobación

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, aprobación), y = aprobación)) +
  coord_flip()

4.2.9 Reprobación

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, reprobación), y = reprobación)) +
  coord_flip()

4.2.10 Repitencia

ggplot(data_educacion) +
  geom_point(aes(x = reorder(etc, repitencia), y = repitencia)) +
  coord_flip()

4.3 Analisis univariado dataset Armas

Aquí se tiene el analisis univariado para las siguientes variables: Departamento Municipio Día Clase de arma Zona Clase de sitio

A continuación empezamos a analizar cada una de las variables listadas. Vamos a observar como esta la distribución de estos datos.

data_armas<-data_incauta_tidy
columns_f_l_armas <- c("departamento", "municipio", "dia","clase_de_arma", "zona", "clase_de_sitio")
data_hurto_f_l_armas <- data_armas[, colnames(data_armas) %in% columns_f_l_armas]
summary(data_hurto_f_l_armas)
##              departamento              municipio            dia      
##  CUNDINAMARCA      :3218   BOGOTÁ D.C. (CT) : 1829   Domingo  :3172  
##  VALLE             :1999   BARRANQUILLA (CT): 1066   Jueves   :3061  
##  ANTIOQUIA         :1958   CALI (CT)        : 1061   Lunes    :2876  
##  ATLÁNTICO         :1648   MEDELLÍN (CT)    :  563   Martes   :2736  
##  SANTANDER         :1488   CÚCUTA (CT)      :  403   Miércoles:2802  
##  NORTE DE SANTANDER:1003   CARTAGENA (CT)   :  375   Sábado   :2840  
##  (Other)           :9194   (Other)          :15211   Viernes  :3021  
##            clase_de_arma      zona      
##  REVOLVER         :8695   RURAL : 6150  
##  ESCOPETA         :5503   URBANA:14358  
##  PISTOLA          :4573                 
##  ESCOPETA DE FISTO:1440                 
##  FUSIL / RIFLE    : 154                 
##  SUBAMETRALLADORA :  82                 
##  (Other)          :  61                 
##                      clase_de_sitio 
##  VIAS PUBLICAS              :14030  
##  FINCAS Y SIMILARES         : 1408  
##  CARRETERA                  : 1301  
##  CASAS DE HABITACION        : 1014  
##  TRAMO DE VIA               :  672  
##  INSTALACIONES DE LA POLICIA:  411  
##  (Other)                    : 1672
plot_factor <- function(data, column, top = 30) {
  group_count <- data %>%
    group_by_(column) %>%
    summarise(
      cantidad_armas = n()
    ) %>%
    arrange(desc(cantidad_armas)) %>%
    top_n(top)
  ggplot(group_count) +
    geom_bar(
      aes_string(x = paste0("reorder(", column, ", cantidad_armas)"), y = "cantidad_armas"),
      stat = "identity"
    ) +
    coord_flip() +
    labs(x = column, y = "Cantidad reportada de armas incautadas") +
    theme(axis.text.y = element_text(size = (rel(0.8))))
}

4.3.1 Departamentos

plot_factor(data_hurto_f_l_armas, "departamento", 20)
## Selecting by cantidad_armas

4.3.2 Municipio

plot_factor(data_hurto_f_l_armas, "municipio", 20)
## Selecting by cantidad_armas

4.3.3 Día

plot_factor(data_hurto_f_l_armas, "dia", 20)
## Selecting by cantidad_armas

4.3.4 Clase de arma empleada

plot_factor(data_hurto_f_l_armas, "clase_de_arma", 20)
## Selecting by cantidad_armas

4.3.5 Zona

plot_factor(data_hurto_f_l_armas, "zona", 20)
## Selecting by cantidad_armas

4.3.6 Clase de sitio

plot_factor(data_hurto_f_l_armas, "clase_de_sitio", 20)
## Selecting by cantidad_armas

5 Analisis Multivariado

5.1 Hurto

Se utilizara esta funcion para obtener la moda de un factor de los municipios

get_mode <- function(var) {
  uniqv <- unique(var)
  uniqv[which.max(tabulate(match(var, uniqv)))]
}

5.1.1 Escolaridad

5.1.1.1 Indice <= 10

esc_mode <- data_hurto_f %>%
  select(municipio, escolaridad) %>%
  group_by(municipio) %>%
  summarise(
    moda_escolaridad = get_mode(escolaridad)
  )

esc_joined <- muni_joined %>%
  filter(indice_hurtos <= 10) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(esc_joined, aes(x = moda_escolaridad, y = indice_hurtos, fill = moda_escolaridad)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X")

5.1.1.2 Indice <= 2

esc_mode <- data_hurto_f %>%
  select(municipio, escolaridad) %>%
  group_by(municipio) %>%
  summarise(
    moda_escolaridad = get_mode(escolaridad)
  )

esc_joined <- muni_joined %>%
  filter(indice_hurtos <= 2) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(esc_joined, aes(x = moda_escolaridad, y = indice_hurtos, fill = moda_escolaridad)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X")

5.1.2 Dia

5.1.2.1 Indice <= 10

esc_mode <- data_hurto_f %>%
  select(municipio, dia) %>%
  group_by(municipio) %>%
  summarise(
    moda_dia = get_mode(dia)
  )

dia_joined <- muni_joined %>%
  filter(indice_hurtos <= 10) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(dia_joined, aes(x = moda_dia, y = indice_hurtos, fill = moda_dia)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X")

5.1.2.2 Indice <= 2

esc_mode <- data_hurto_f %>%
  select(municipio, dia) %>%
  group_by(municipio) %>%
  summarise(
    moda_dia = get_mode(dia)
  )

dia_joined <- muni_joined %>%
  filter(indice_hurtos <= 2) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(dia_joined, aes(x = moda_dia, y = indice_hurtos, fill = moda_dia)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X")

5.1.3 Movil Agresor

5.1.3.1 Indice <= 10

esc_mode <- data_hurto_f %>%
  select(municipio, movil_agresor) %>%
  group_by(municipio) %>%
  summarise(
    moda_movil_agresor = get_mode(movil_agresor)
  )

movil_agresor_joined <- muni_joined %>%
  filter(indice_hurtos <= 10) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(movil_agresor_joined, aes(x = moda_movil_agresor, y = indice_hurtos, fill = moda_movil_agresor)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X") +
  coord_flip()

5.1.3.2 Indice <= 2

esc_mode <- data_hurto_f %>%
  select(municipio, movil_agresor) %>%
  group_by(municipio) %>%
  summarise(
    moda_movil_agresor = get_mode(movil_agresor)
  )

movil_agresor_joined <- muni_joined %>%
  filter(indice_hurtos <= 2) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(movil_agresor_joined, aes(x = moda_movil_agresor, y = indice_hurtos, fill = moda_movil_agresor)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X") +
  coord_flip()

5.1.4 Edad

5.1.4.1 Indice <= 10

esc_mode <- data_hurto_f %>%
  select(municipio, edad) %>%
  group_by(municipio) %>%
  summarise(
    moda_edad = mean(edad)
  )

edad_joined <- muni_joined %>%
  filter(indice_hurtos <= 10) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(edad_joined, aes(x = moda_edad, y = indice_hurtos, fill = moda_edad)) +
  geom_point() +
  theme(legend.position = "X")

5.1.4.2 Indice <= 2

esc_mode <- data_hurto_f %>%
  select(municipio, edad) %>%
  group_by(municipio) %>%
  summarise(
    moda_edad = mean(edad)
  )

edad_joined <- muni_joined %>%
  filter(indice_hurtos <= 2) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(edad_joined, aes(x = moda_edad, y = indice_hurtos, fill = moda_edad)) +
  geom_point() +
  theme(legend.position = "X")

5.1.5 Estado Civil

5.1.5.1 Indice <= 10

esc_mode <- data_hurto_f %>%
  select(municipio, estado_civil) %>%
  group_by(municipio) %>%
  summarise(
    moda_estado_civil = get_mode(estado_civil)
  )

estado_civil_joined <- muni_joined %>%
  filter(indice_hurtos <= 10) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(estado_civil_joined, aes(x = moda_estado_civil, y = indice_hurtos, fill = moda_estado_civil)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X")

5.1.5.2 Indice <= 2

esc_mode <- data_hurto_f %>%
  select(municipio, estado_civil) %>%
  group_by(municipio) %>%
  summarise(
    moda_estado_civil = get_mode(estado_civil)
  )

estado_civil_joined <- muni_joined %>%
  filter(indice_hurtos <= 2) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(estado_civil_joined, aes(x = moda_estado_civil, y = indice_hurtos, fill = moda_estado_civil)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X")

5.1.6 Clase de Empleado

5.1.6.1 Indice <= 10

esc_mode <- data_hurto_f %>%
  select(municipio, clase_de_empleado) %>%
  group_by(municipio) %>%
  summarise(
    moda_clase_de_empleado = get_mode(clase_de_empleado)
  )

clase_de_empleado_joined <- muni_joined %>%
  filter(indice_hurtos <= 10) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(clase_de_empleado_joined, aes(x = moda_clase_de_empleado, y = indice_hurtos, fill = moda_clase_de_empleado)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X") +
  coord_flip()

5.1.6.2 Indice <= 2

esc_mode <- data_hurto_f %>%
  select(municipio, clase_de_empleado) %>%
  group_by(municipio) %>%
  summarise(
    moda_clase_de_empleado = get_mode(clase_de_empleado)
  )

clase_de_empleado_joined <- muni_joined %>%
  filter(indice_hurtos <= 2) %>%
  left_join(esc_mode, by = c("municipio", "municipio"), copy = TRUE)
## Warning: Column `municipio` joining character vector and factor, coercing
## into character vector
ggplot(clase_de_empleado_joined, aes(x = moda_clase_de_empleado, y = indice_hurtos, fill = moda_clase_de_empleado)) +
  geom_boxplot(alpha = 0.4) +
  theme(legend.position = "X") +
  coord_flip()

5.1.7 Arma Empleada

arma_spread <- data_hurto %>%
  count(municipio, arma_empleada) %>%
  group_by(municipio) %>%
  mutate(prop = n / sum(n)) %>%
  select(-n) %>%
  spread(key = arma_empleada, value = prop)

arma_spread
## # A tibble: 897 x 16
## # Groups:   municipio [899]
##    municipio ALUCINOGENOS `ARMA BLANCA / … `ARMA DE FUEGO` CONTUNDENTES
##    <fct>            <dbl>            <dbl>           <dbl>        <dbl>
##  1 ABEJORRAL           NA           0.0625          0.0625       0.125 
##  2 ABREGO              NA           0.1             0.3          0.1   
##  3 ABRIAQUÍ            NA          NA              NA            0.5   
##  4 ACACÍAS             NA           0.116           0.0773       0.159 
##  5 ACANDÍ              NA           0.2             0.2         NA     
##  6 ACEVEDO             NA           0.182           0.364       NA     
##  7 ACHÍ                NA          NA              NA           NA     
##  8 AGRADO              NA          NA               0.286       NA     
##  9 AGUA DE …           NA           0.0909         NA            0.0909
## 10 AGUACHICA           NA           0.142           0.432        0.0169
## # … with 887 more rows, and 11 more variables: CORTANTES <dbl>,
## #   DIRECTA <dbl>, ESCOPOLAMINA <dbl>, JERINGA <dbl>, `LLAVE
## #   MAESTRA` <dbl>, `NO REPORTADO` <dbl>, PALANCAS <dbl>, PERRO <dbl>,
## #   `SIN EMPLEO DE ARMAS` <dbl>, `SUSTANCIAS TOXICAS` <dbl>,
## #   VEHICULO <dbl>
remove_capital_2 <- function(city_factor2) {
  city <- as.character(city_factor2)
  no_capital <- gsub(" \\(CT\\)", "", city)

  return(no_capital)
}

arma_spread <- arma_spread %>%
  left_join(muni_joined_sorted, by = c("municipio" = "municipio"), copy = TRUE)
## Warning: Column `municipio` joining factor and character vector, coercing
## into character vector
head(arma_spread)
## # A tibble: 6 x 19
## # Groups:   municipio [6]
##   municipio ALUCINOGENOS `ARMA BLANCA / … `ARMA DE FUEGO` CONTUNDENTES
##   <chr>            <dbl>            <dbl>           <dbl>        <dbl>
## 1 ABEJORRAL           NA           0.0625          0.0625        0.125
## 2 ABREGO              NA           0.1             0.3           0.1  
## 3 ABRIAQUÍ            NA          NA              NA             0.5  
## 4 ACACÍAS             NA           0.116           0.0773        0.159
## 5 ACANDÍ              NA           0.2             0.2          NA    
## 6 ACEVEDO             NA           0.182           0.364        NA    
## # … with 14 more variables: CORTANTES <dbl>, DIRECTA <dbl>,
## #   ESCOPOLAMINA <dbl>, JERINGA <dbl>, `LLAVE MAESTRA` <dbl>, `NO
## #   REPORTADO` <dbl>, PALANCAS <dbl>, PERRO <dbl>, `SIN EMPLEO DE
## #   ARMAS` <dbl>, `SUSTANCIAS TOXICAS` <dbl>, VEHICULO <dbl>,
## #   poblacion_2017 <int>, cantidad_hurtos <int>, indice_hurtos <dbl>
arma_spread <- arma_spread[order(-arma_spread$indice_hurtos),]
head(arma_spread)
## # A tibble: 6 x 19
## # Groups:   municipio [6]
##   municipio ALUCINOGENOS `ARMA BLANCA / … `ARMA DE FUEGO` CONTUNDENTES
##   <chr>            <dbl>            <dbl>           <dbl>        <dbl>
## 1 ARMENIA             NA            0.253           0.125       0.125 
## 2 FLORENCIA           NA            0.285           0.162       0.0686
## 3 SAN ANDR…           NA            0.104           0.111       0.0465
## 4 CALDAS              NA            0.121           0.319       0.0638
## 5 SABANALA…           NA            0.138           0.319       0.0426
## 6 RIONEGRO            NA            0.159           0.156       0.142 
## # … with 14 more variables: CORTANTES <dbl>, DIRECTA <dbl>,
## #   ESCOPOLAMINA <dbl>, JERINGA <dbl>, `LLAVE MAESTRA` <dbl>, `NO
## #   REPORTADO` <dbl>, PALANCAS <dbl>, PERRO <dbl>, `SIN EMPLEO DE
## #   ARMAS` <dbl>, `SUSTANCIAS TOXICAS` <dbl>, VEHICULO <dbl>,
## #   poblacion_2017 <int>, cantidad_hurtos <int>, indice_hurtos <dbl>
ggplot(arma_spread) + 
  stat_smooth(mapping = aes(x=arma_spread$`ARMA BLANCA / CORTOPUNZANTE`, y=arma_spread$indice_hurtos))
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).

ggplot(arma_spread, aes(x=arma_spread$`ARMA BLANCA / CORTOPUNZANTE`, y=indice_hurtos)) +
  geom_point() +ylim(0, 7) + xlim(0,1)
## Warning: Removed 472 rows containing missing values (geom_point).

ggplot(arma_spread, aes(x=arma_spread$`ARMA DE FUEGO`, y=indice_hurtos)) +
  geom_point()+ylim(0, 7) + xlim(0,1)
## Warning: Removed 363 rows containing missing values (geom_point).

5.2 Educación y Hurto

str(edu_joined)
## 'data.frame':    59 obs. of  38 variables:
##  $ municipio                  : chr  "MEDELLÍN" "BELLO" "CALDAS" "NARIÑO" ...
##  $ poblacion_2017             : int  2508452 473423 79652 17686 124219 1228271 649111 1024882 12342 123906 ...
##  $ cantidad_hurtos            : int  17522 1594 141 9 654 5585 1079 1954 14 160 ...
##  $ indice_hurtos              : num  6.985 3.367 1.77 0.509 5.265 ...
##  $ población_5_16             : int  370202 93422 125643 223685 24795 237521 140244 210840 267545 28640 ...
##  $ tasa_matriculación_5_16    : num  101.3 78.5 73.6 63.5 82.8 ...
##  $ cobertura_neta             : num  101.2 78.5 73.5 63.5 82.5 ...
##  $ cobertura_neta_transición  : num  73.1 53.4 48.6 33 57 ...
##  $ cobertura_neta_primaria    : num  98.6 77.2 67.7 59.3 76.6 ...
##  $ cobertura_neta_secundaria  : num  89.9 67.3 65.1 50.5 74 ...
##  $ cobertura_neta_media       : num  54.9 38.3 40.5 25.5 46.3 ...
##  $ cobertura_bruta            : num  116.3 89.8 84.3 76.2 94 ...
##  $ cobertura_bruta_transición : num  88.5 65.6 61.1 60.1 70.9 ...
##  $ cobertura_bruta_primaria   : num  114 91.3 84.8 85.4 90.2 ...
##  $ cobertura_bruta_secundaria : num  130.2 101.8 93.4 78.9 106.5 ...
##  $ cobertura_bruta_media      : num  107.6 74.4 75.9 56.1 89.3 ...
##  $ tamaño_promedio_de_grupo   : num  34 34.5 26.5 17 31.1 ...
##  $ sedes_conectadas_a_internet: num  98.3 93.7 31.2 21.6 100 ...
##  $ deserción                  : num  3.46 3.06 3.73 1.52 3.92 1.14 1.22 2.77 3.1 3.31 ...
##  $ deserción_transición       : num  3.05 2.94 3.8 1.18 2.38 1.84 1.9 4.26 2.93 6.62 ...
##  $ deserción_primaria         : num  2.71 2.71 2.85 1.03 2.41 1.05 1.24 2.33 2.11 2.82 ...
##  $ deserción_secundaria       : num  4.68 3.82 4.95 2.06 6.06 1.21 1.23 3.1 4.33 3.49 ...
##  $ deserción_media            : num  2.8 2.14 3.28 2.15 3.38 0.86 0.74 2.51 3.9 2.12 ...
##  $ aprobación                 : num  85.3 96.1 88.6 97.4 80.2 ...
##  $ aprobación_transición      : num  96.8 96.7 95.8 98.3 97 ...
##  $ aprobación_primaria        : num  88.6 96.5 91 97.9 86.1 ...
##  $ aprobación_secundaria      : num  77.8 95.3 83.8 96.7 69.3 ...
##  $ aprobación_media           : num  89.6 97 90.4 97.1 85 ...
##  $ reprobación                : num  11.23 0.84 7.64 1.06 15.87 ...
##  $ reprobación_transición     : num  0.15 0.36 0.37 0.48 0.62 1.84 0.77 0.41 0.12 0.52 ...
##  $ reprobación_primaria       : num  8.7 0.83 6.14 1.11 11.53 ...
##  $ reprobación_secundaria     : num  17.51 0.92 11.23 1.21 24.61 ...
##  $ reprobación_media          : num  7.57 0.83 6.36 0.73 11.64 ...
##  $ repitencia                 : num  10.16 1.45 2.08 2.61 11.91 ...
##  $ repitencia_transición      : num  1.37 0.25 0.28 0.9 1.76 1.36 0.47 7.78 1.91 3.05 ...
##  $ repitencia_primaria        : num  8.96 1.48 1.64 2.3 9.87 1.42 0.35 7.35 2.98 3.4 ...
##  $ repitencia_secundaria      : num  14.98 1.96 3.32 3.75 17.17 ...
##  $ repitencia_media           : num  4.83 0.41 0.98 1.46 7.9 0.35 0.2 3.82 1.63 1.86 ...

5.2.1 Tasa Matriculación personas entre 5 y 16 años

ggplot(edu_joined) +
  geom_point(aes(x = tasa_matriculación_5_16, y = indice_hurtos))

5.2.2 Tamaño Promedio de Grupo

ggplot(edu_joined) +
  geom_point(aes(x = tamaño_promedio_de_grupo, y = indice_hurtos))

5.2.3 Sedes Conectadas a Internet

ggplot(edu_joined) +
  geom_point(aes(x = sedes_conectadas_a_internet, y = indice_hurtos))

5.2.4 % Cobertura

5.2.4.1 Neta

ggplot(edu_joined) +
  geom_point(aes(x = cobertura_neta, y = indice_hurtos))

5.2.4.2 Transición

ggplot(edu_joined) +
  geom_point(aes(x = cobertura_neta_transición, y = indice_hurtos))

5.2.4.3 Primaria

ggplot(edu_joined) +
  geom_point(aes(x = cobertura_neta_primaria, y = indice_hurtos))

5.2.4.4 Secundaria

ggplot(edu_joined) +
  geom_point(aes(x = cobertura_neta_secundaria, y = indice_hurtos))

5.2.4.5 Media

ggplot(edu_joined) +
  geom_point(aes(x = cobertura_neta_media, y = indice_hurtos))

5.2.5 % Deserción

5.2.5.1 Neta

ggplot(edu_joined) +
  geom_point(aes(x = deserción, y = indice_hurtos))

5.2.5.2 Transición

ggplot(edu_joined) +
  geom_point(aes(x = deserción_transición, y = indice_hurtos))

5.2.5.3 Primaria

ggplot(edu_joined) +
  geom_point(aes(x = deserción_primaria, y = indice_hurtos))

5.2.5.4 Secundaria

ggplot(edu_joined) +
  geom_point(aes(x = deserción_secundaria, y = indice_hurtos))

5.2.5.5 Media

ggplot(edu_joined) +
  geom_point(aes(x = deserción_media, y = indice_hurtos))

5.2.6 % Aprobación

5.2.6.1 Neta

ggplot(edu_joined) +
  geom_point(aes(x = aprobación, y = indice_hurtos))

5.2.6.2 Transición

ggplot(edu_joined) +
  geom_point(aes(x = aprobación_transición, y = indice_hurtos))

5.2.6.3 Primaria

ggplot(edu_joined) +
  geom_point(aes(x = aprobación_primaria, y = indice_hurtos))

5.2.6.4 Secundaria

ggplot(edu_joined) +
  geom_point(aes(x = aprobación_secundaria, y = indice_hurtos))

5.2.6.5 Media

ggplot(edu_joined) +
  geom_point(aes(x = aprobación_media, y = indice_hurtos))

5.2.7 % Reprobación

5.2.7.1 Neta

ggplot(edu_joined) +
  geom_point(aes(x = reprobación, y = indice_hurtos))

5.2.7.2 Transición

ggplot(edu_joined) +
  geom_point(aes(x = reprobación_transición, y = indice_hurtos))

5.2.7.3 Primaria

ggplot(edu_joined) +
  geom_point(aes(x = reprobación_primaria, y = indice_hurtos))

5.2.7.4 Secundaria

ggplot(edu_joined) +
  geom_point(aes(x = reprobación_secundaria, y = indice_hurtos))

5.2.7.5 Media

ggplot(edu_joined) +
  geom_point(aes(x = reprobación_media, y = indice_hurtos))

5.3 Analisis multivariado dataset armas incautadas

El dataset de armas incautadas fue seleccionado pues, se cuenta con la hipotesis de a mayor cantidad de armas incautadas, menor serà el indice de hurtos. De manera que se pasa a realizar un analisis multivariado con dicha variable. A continuaciòn los resultados:

head(data_hurto_f_l_armas)
##   departamento    municipio     dia clase_de_arma   zona
## 1     AMAZONAS LETICIA (CT) Domingo      REVOLVER  RURAL
## 2    ANTIOQUIA        ANORÍ Domingo      REVOLVER URBANA
## 3    ANTIOQUIA     FREDONIA Domingo      REVOLVER  RURAL
## 4    ANTIOQUIA  SAN VICENTE Domingo       PISTOLA  RURAL
## 5    ANTIOQUIA     SOPETRÁN Domingo      ESCOPETA  RURAL
## 6      BOLÍVAR  MONTECRISTO Domingo      CARABINA  RURAL
##       clase_de_sitio
## 1      VIAS PUBLICAS
## 2      VIAS PUBLICAS
## 3      VIAS PUBLICAS
## 4 FINCAS Y SIMILARES
## 5 FINCAS Y SIMILARES
## 6     ZONA SELVÁTICA
munic_spread <- data_hurto_f_l_armas %>%
  group_by(municipio) %>%
  summarize(
    cantidad_incauta = n()
  )

munic_spread
## # A tibble: 978 x 2
##    municipio    cantidad_incauta
##    <fct>                   <int>
##  1 ABEJORRAL                  16
##  2 ABREGO                     24
##  3 ABRIAQUÍ                    1
##  4 ACACÍAS                    35
##  5 ACANDÍ                      6
##  6 ACEVEDO                     2
##  7 ACHÍ                        2
##  8 AGRADO                      4
##  9 AGUA DE DIOS                2
## 10 AGUACHICA                  70
## # … with 968 more rows
munic_spread_sorted <- munic_spread[order(-munic_spread$cantidad_incauta),]
munic_spread_sorted
## # A tibble: 978 x 2
##    municipio         cantidad_incauta
##    <fct>                        <int>
##  1 BOGOTÁ D.C. (CT)              1829
##  2 BARRANQUILLA (CT)             1066
##  3 CALI (CT)                     1061
##  4 MEDELLÍN (CT)                  563
##  5 CÚCUTA (CT)                    403
##  6 CARTAGENA (CT)                 375
##  7 BUCARAMANGA (CT)               269
##  8 SOLEDAD                        269
##  9 MANIZALES (CT)                 261
## 10 PEREIRA (CT)                   217
## # … with 968 more rows
remove_capital_2 <- function(city_factor2) {
  city <- as.character(city_factor2)
  no_capital <- gsub(" \\(CT\\)", "", city)

  return(no_capital)
}

munic_spread_sorted$municipio <- as.factor(sapply(munic_spread_sorted$municipio, remove_capital_2))
munic_spread_sorted
## # A tibble: 978 x 2
##    municipio    cantidad_incauta
##    <fct>                   <int>
##  1 BOGOTÁ D.C.              1829
##  2 BARRANQUILLA             1066
##  3 CALI                     1061
##  4 MEDELLÍN                  563
##  5 CÚCUTA                    403
##  6 CARTAGENA                 375
##  7 BUCARAMANGA               269
##  8 SOLEDAD                   269
##  9 MANIZALES                 261
## 10 PEREIRA                   217
## # … with 968 more rows
head(munic_spread_sorted)
## # A tibble: 6 x 2
##   municipio    cantidad_incauta
##   <fct>                   <int>
## 1 BOGOTÁ D.C.              1829
## 2 BARRANQUILLA             1066
## 3 CALI                     1061
## 4 MEDELLÍN                  563
## 5 CÚCUTA                    403
## 6 CARTAGENA                 375
head(muni_joined_sorted)
##         municipio poblacion_2017 cantidad_hurtos indice_hurtos
## 149   BOGOTÁ D.C.        8080734           64188      7.943338
## 1        MEDELLÍN        2508452           17522      6.985184
## 1006         CALI        2420114           14681      6.066243
## 126  BARRANQUILLA        1228271            5585      4.547042
## 150     CARTAGENA        1024882            1954      1.906561
## 780        CÚCUTA         662673            2267      3.420993
munic_spread_sorted <- munic_spread_sorted %>%
  left_join(muni_joined_sorted, by = c("municipio" = "municipio"), copy = TRUE)

head(munic_spread_sorted)
## # A tibble: 6 x 5
##   municipio   cantidad_incauta poblacion_2017 cantidad_hurtos indice_hurtos
##   <chr>                  <int>          <int>           <int>         <dbl>
## 1 BOGOTÁ D.C.             1829        8080734           64188          7.94
## 2 BARRANQUIL…             1066        1228271            5585          4.55
## 3 CALI                    1061        2420114           14681          6.07
## 4 MEDELLÍN                 563        2508452           17522          6.99
## 5 CÚCUTA                   403         662673            2267          3.42
## 6 CARTAGENA                375        1024882            1954          1.91
munic_spread_sorted <- munic_spread_sorted[order(-munic_spread_sorted$cantidad_incauta),]

str(munic_spread_sorted)
## Classes 'tbl_df', 'tbl' and 'data.frame':    1063 obs. of  5 variables:
##  $ municipio       : chr  "BOGOTÁ D.C." "BARRANQUILLA" "CALI" "MEDELLÍN" ...
##  $ cantidad_incauta: int  1829 1066 1061 563 403 375 269 269 261 217 ...
##  $ poblacion_2017  : int  8080734 1228271 2420114 2508452 662673 1024882 528497 649111 398830 474335 ...
##  $ cantidad_hurtos : int  64188 5585 14681 17522 2267 1954 4068 1079 1883 2701 ...
##  $ indice_hurtos   : num  7.94 4.55 6.07 6.99 3.42 ...
ggplot(munic_spread_sorted) + 
  stat_smooth(mapping = aes(x=munic_spread_sorted$cantidad_incauta, y=munic_spread_sorted$indice_hurtos)) + 
  xlab("cantidad armas incautadas") + 
  ylab("indice hurtos")
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

munic_spread_sorted<-head(munic_spread_sorted,30)
munic_spread_sorted
## # A tibble: 30 x 5
##    municipio  cantidad_incauta poblacion_2017 cantidad_hurtos indice_hurtos
##    <chr>                 <int>          <int>           <int>         <dbl>
##  1 BOGOTÁ D.…             1829        8080734           64188          7.94
##  2 BARRANQUI…             1066        1228271            5585          4.55
##  3 CALI                   1061        2420114           14681          6.07
##  4 MEDELLÍN                563        2508452           17522          6.99
##  5 CÚCUTA                  403         662673            2267          3.42
##  6 CARTAGENA               375        1024882            1954          1.91
##  7 BUCARAMAN…              269         528497            4068          7.70
##  8 SOLEDAD                 269         649111            1079          1.66
##  9 MANIZALES               261         398830            1883          4.72
## 10 PEREIRA                 217         474335            2701          5.69
## # … with 20 more rows
ggplot(munic_spread_sorted, aes(x=cantidad_incauta, y=indice_hurtos)) +
  geom_point()+geom_smooth() +ylim(0, 7) + xlim(0,500)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'